//
//  ZCRankingListDetailVC.m
//  zctx
//
//  Created by apple on 16/2/24.
//  Copyright © 2016年 sanliang. All rights reserved.
//

#import "ZCRankingListDetailVC.h"
#import "ActionView.h"
#import "ZCRankingDeatailView.h"
#import "ZCRankingListModelContent.h"
@interface ZCRankingListDetailVC ()
@property (nonatomic,strong)UIScrollView *scrolloView;
@property (nonatomic,strong)UIImageView *imageView;
@end

@implementation ZCRankingListDetailVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear: animated];
//    self.tabBarController.hidesBottomBarWhenPushed = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F1FBFE"];
    [self initnavegation];
    self.navigationItem.title = @"食品安全小卫士评选";
    [self.view addSubview:self.scrolloView];
    [self.scrolloView addSubview:self.imageView];
    self.imageView.frame = CGRectMake(0,0,SCREEN_WIDTH,192);
    [self addRankingDetail];
    
    NSLog(@"model = %@",self.detailModel);

}
#pragma mark 导航栏
-(void)initnavegation{
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 19, 36);
    [leftButton setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_leftNavBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barButtonItem_leftNavBar;
}

-(void)backButtonPressed{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)addRankingDetail{
    
    ZCRankingDeatailView *rankingView = [[ZCRankingDeatailView alloc]initWithFrame:CGRectMake(0, 192,SCREEN_WIDTH,SCREEN_HEIGHT) andDetail:self.detailModel];
    [self.scrolloView addSubview:rankingView];
    rankingView.shareClick = ^{
        ActionView *action = [[ActionView alloc]initWithFrame:CGRectZero];
        action.isweb =3;
        action.pid = self.detailModel.contentIdentifier;
        [action showInView:self.view];
    };
}

-(void)setUpInfo{
    UIView *infoView = [[UIView alloc]initWithFrame:CGRectMake(19, 192+18, SCREEN_WIDTH-38, 500)];
    infoView.backgroundColor = [UIColor colorWithHexString:@"#8CDFFE"];
    [self.scrolloView addSubview:infoView];
    //numLable
    UILabel *numLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [infoView addSubview:numLable];
    numLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    numLable.text = [NSString stringWithFormat:@"共计%@票",self.detailModel.voteNum];
    numLable.textAlignment = NSTextAlignmentRight;
    numLable.font = [UIFont systemFontOfSize:15];
    [numLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(infoView.top).with.offset(15);
        make.right.equalTo(infoView.right).with.offset(-15);
        make.height.mas_equalTo(@21);
        make.width.mas_equalTo(@100);
    }];
    
    UILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [infoView addSubview:nameLable];
    nameLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    nameLable.text = [NSString stringWithFormat:@"%@ %@号",self.detailModel.vote_name,self.detailModel.contentIdentifier];
    nameLable.font = [UIFont systemFontOfSize:15];
    [nameLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(infoView.top).with.offset(15);
        make.left.equalTo(infoView.left).with.offset(15);
        make.right.equalTo(numLable.left).with.offset(15);
        make.height.mas_equalTo(@21);
    }];
    
    UILabel *contentLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [infoView addSubview:contentLable];
    contentLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    contentLable.text = self.detailModel.slogan;
    contentLable.font = [UIFont systemFontOfSize:15];
    [contentLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLable.bottom).with.offset(5);
        make.left.equalTo(infoView.left).with.offset(15);
        make.right.equalTo(infoView.right).with.offset(-15);
        make.height.mas_equalTo(@21);
    }];
    
    UIImageView *imgView = [[UIImageView alloc]init];
    [infoView addSubview:imgView];
    [imgView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(contentLable.bottom).with.offset(8);
        make.left.equalTo(infoView.left).with.offset(15);
        make.right.equalTo(infoView.right).with.offset(-15);
        make.bottom.equalTo(infoView.bottom).with.offset(-24);
    }];
    NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[NetworkManager strURLBasic],self.detailModel.thumb]];
    NSLog(@"url = %@ , %@ , %@",url,[NetworkManager strURLBasic],self.detailModel.thumb);
    [imgView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placehold_involved"]];
    
    UIButton *shareButton = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.scrolloView addSubview:shareButton];
    [shareButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.scrolloView.centerX).with.offset(0);
        make.top.equalTo(infoView.bottom).with.offset(33);
        make.height.mas_equalTo(@40);
        make.width.mas_equalTo(@250);
    }];
    shareButton.layer.cornerRadius = 20;
    shareButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [shareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shareButton.backgroundColor = [UIColor colorWithHexString:@"#FFBE3C"];
    [shareButton addTarget:self action:@selector(showShareView) forControlEvents:UIControlEventTouchUpInside];

}

#pragma mark 点击分享
-(void)showShareView{
    ActionView *action = [[ActionView alloc]initWithFrame:CGRectZero];
    action.isweb =3;
    action.pid = self.detailModel.contentIdentifier;
    [action showInView:self.view];
}

-(UIScrollView *)scrolloView{
    if (!_scrolloView) {
        _scrolloView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT)];
        _scrolloView.showsHorizontalScrollIndicator = YES;
        _scrolloView.showsVerticalScrollIndicator = YES;
        _scrolloView.contentSize = CGSizeMake(SCREEN_WIDTH,SCREEN_WIDTH*2.1);
    }
    return _scrolloView;
}

-(UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        _imageView.image = [UIImage imageNamed:@"enroll_head"];
    }
    return _imageView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
